package com.ruoyi.common.core.rabbitmq;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

@Component
public class RabbitMqUtils {
    @Autowired
    private RabbitTemplate rabbitTemplate;



    /**
     * 发送rabbitmq消息给前端
     * @author Yu
     * @param exchange    交换机
     * @param uesrSet     推送用户列表
     * @param title       推送标题
     * @param msgbody     推送内容
     * @param tourl       弹窗点击跳转地址
     * @return void
     */
    public void sendRabbitBpmMsg(String exchange,  HashSet<String> uesrSet, String title, String msgbody, String tourl, String tenantId){
        Set<String> nowspr = new HashSet<>();
        nowspr = uesrSet;
        if(nowspr != null) {
            for (String user : nowspr) {
                HashMap<String,String> remsg= new HashMap<>();
                remsg.put("msgbody",msgbody);
                remsg.put("title",title);
                remsg.put("tourl",tourl);
                rabbitTemplate.convertAndSend(exchange, "inform.bpm." + tenantId + "." + user, JSONObject.parse(JSONObject.toJSONString(remsg)));
            }
        }
    }
}
